package models;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.OneToMany;

import play.data.validation.MaxSize;
import play.db.jpa.Model;

@Entity
public class Course extends Model
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -2554801896957930125L;

	@Column( length = 8 )
	public String code;

	@Column( length = 32 )
	public String title;

	@Lob
	@MaxSize( 10000 )
	public String description;

	@OneToMany( mappedBy = "course" )
	public List<Assignment> assignments;

	@OneToMany( mappedBy = "course" )
	public List<Tutorial> tutorials;

	public String toString()
	{
		return code + " " + title;
	}

	public int getTotalRequests()
	{
		return CourseRequest.find( "byTutorial.course", this ).fetch().size();
	}
}
